import { 
	getDepartment, 
	startDepartment,
	addDepartmentSon,
	addDepartment,
	deleteDepartmentList,
	updateDepartment,
	updateDepartmentSon,
	deleteDepartment,
	deleteDepartmentSon
} from '@/api/index'

const state = {
	departmentList: []
}

const mutations = {
	getDepartment(state, res){
		state.departmentList = res.data
	}
}

const actions = {
	// 获取部门列表
	async getDepartment({commit}) {
		let res = await getDepartment()
		commit('getDepartment', res)
		return res
	},
	// 部门开关
	async startDepartment({commit}, data) {
		let res = await startDepartment(data)
		return res
	},
	// 添加子部门
	async addDepartmentSon({commit}, data) {
		let res = await addDepartmentSon(data)
		return res
	},
	// 添加部门
	async addDepartment({commit}, data) {
		let res = await addDepartment(data)
		return res
	},
	// 批量删除部门
	async deleteDepartmentList({commit}, data) {
		let res = await deleteDepartmentList(data)
		return res
	},
	// 更新一级部门
	async updateDepartment({commit}, data) {
		let res = await updateDepartment(data)
		return res
	},
	// 更新二级部门
	async updateDepartmentSon({commit}, data) {
		let res = await updateDepartmentSon(data)
		return res
	},
	// 删除一级部门
	async deleteDepartment({commit}, data) {
		let res = await deleteDepartment(data)
		return res
	},
	// 删除二级部门
	async deleteDepartmentSon({commit}, data){
		let res = await deleteDepartmentSon(data)
		return res
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}